<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>正则表达式</title>
    <script>
        str = "avcergajcloJakcaic"

        let re = /a([a-z]c)/ig
        //exec()获取第一个符合正则表达式的内容
        let result = re.exec(str)

        //如果还有符合的内容就输出，该循环可把所有符合的内容输出
        while(result){
            console.log(result[0]);
            //给正则表达式re添加了一个括号，则result1得到全部内容如avc，result2得到括号里内容如vc
            console.log(result[1]);
            result = re.exec(str)
        }

        /*
        取手机号练习
        */
        let str2 = "safe13756870502sadfa"
        //手机号第二位为1,2,3是客服号
        // let re2 = /1[3-9]\d{9}/g
        //还要取前三位和后四位
        let re2 = /(1[3-9]\d)\d{4}(\d{4})/g

        let result2
        while((result2 = re2.exec(str2))){
            console.log(result2);
            console.log(result2[0], result2[1], result2[2]);
            console.log(result2[1]+"****"+result2[2]);  //137****0502
        }
    </script>
</head>
<body>
    
</body>
</html>